package com.itheima.day10_Map.Test4;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/*
4、【编号：1604】现需要将一些学生对象（属性包含姓名和年龄），
与其地址，一一对应存储，并查看存储效果，要保证学生对象不重复，
请编写程序实现以上需求，运行效果如下：
Student{name='小红', age=20}---北京海淀
Student{name='小黄', age=22}---北京朝阳
Student{name='小白', age=25}---北京海淀
Student{name='小蓝', age=23}---北京顺义
Student{name='小绿', age=21}---北京昌平
 */
public class Demo4 {
    public static void main(String[] args) {
        HashMap<Student,String> hm = new HashMap<>();
        Student stu1 =  new Student("小红",20);
        Student stu2 =  new Student("小黄",22);
        Student stu3 =  new Student("小白",25);
        Student stu4 =  new Student("小蓝",23);
        Student stu5 =  new Student("小绿",21);
        hm.put(stu1,"北京海淀");
        hm.put(stu2,"北京朝阳");
        hm.put(stu3,"北京海淀");
        hm.put(stu4,"北京顺义");
        hm.put(stu5,"北京昌平");
        Set<Map.Entry<Student, String>> entries = hm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"---"+value);
        }

    }
}
